package com.acwing.partition1;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * @author `RKC`
 * @date 2021/11/26 16:55
 */
public class AC5多重背包问题II {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]), m = Integer.parseInt(s[1]);
        int[] weight = new int[n], value = new int[n], count = new int[n];
        for (int i = 0; i < n; i++) {
            s = reader.readLine().split(" ");
            int a = Integer.parseInt(s[0]), b = Integer.parseInt(s[1]), c = Integer.parseInt(s[2]);
            weight[i] = a;
            value[i] = b;
            count[i] = c;
        }
        int ans = dynamicProgramming(weight, value, count, m);
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int dynamicProgramming(int[] weight, int[] value, int[] count, int m) {
        int[] dp = new int[m + 1];
        for (int i = 0; i < weight.length; i++) {
            int w = weight[i], v = value[i], s = count[i];
            for (int k = 1; k <= s; k *= 2) {
                for (int j = m; j >= k * w; j--) {
                    dp[j] = Math.max(dp[j], dp[j - k * w] + k * v);
                }
                s -= k;
            }
            for (int j = m; s != 0 && j >= s * w; j--) dp[j] = Math.max(dp[j], dp[j - s * w] + s * v);
            s = 0;
        }
        return dp[m];
    }
}
